package com.ruoyi.project.query.paeaDsCusvd4.controller;

import java.util.List;

import com.ruoyi.common.utils.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.query.paeaDsCusvd4.domain.PaeaDsCusvd4;
import com.ruoyi.project.query.paeaDsCusvd4.service.IPaeaDsCusvd4Service;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import java.util.Arrays;
import java.util.UUID;

import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 对公客户信息Controller
 *
 * @author gang.wei
 * @date 2020-04-07
 */
@Controller
@RequestMapping("/query/paeaDsCusvd4")
public class PaeaDsCusvd4Controller extends BaseController
{
    private String prefix = "query/paeaDsCusvd4";

    @Autowired
    private IPaeaDsCusvd4Service paeaDsCusvd4Service;

    @RequiresPermissions("query:paeaDsCusvd4:view")
    @GetMapping()
    public String paeaDsCusvd4()
    {
        return prefix + "/paeaDsCusvd4";
    }

    /**
     * 查询对公客户信息列表
     */
    @RequiresPermissions("query:paeaDsCusvd4:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PaeaDsCusvd4 paeaDsCusvd4)
    {
        startPage();
        List<PaeaDsCusvd4> list = paeaDsCusvd4Service.selectPaeaDsCusvd4List(paeaDsCusvd4);
        return getDataTable(list);
    }

    /**
     * 导出对公客户信息列表
     */
    @RequiresPermissions("query:paeaDsCusvd4:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PaeaDsCusvd4 paeaDsCusvd4)
    {
        List<PaeaDsCusvd4> list = paeaDsCusvd4Service.selectPaeaDsCusvd4List(paeaDsCusvd4);
        ExcelUtil<PaeaDsCusvd4> util = new ExcelUtil<PaeaDsCusvd4>(PaeaDsCusvd4.class);
        return util.exportExcel(list, "paeaDsCusvd4");
    }

    /**
     * 新增对公客户信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存对公客户信息
     */
    @RequiresPermissions("query:paeaDsCusvd4:add")
    @Log(title = "对公客户信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PaeaDsCusvd4 paeaDsCusvd4)
    {
        if(StringUtils.isEmpty(paeaDsCusvd4.getId())){paeaDsCusvd4.setId(UUID.randomUUID().toString().replaceAll("-",""));}
        return toAjax(paeaDsCusvd4Service.insertPaeaDsCusvd4(paeaDsCusvd4));
    }

    /**
     * 修改对公客户信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        PaeaDsCusvd4 paeaDsCusvd4 = paeaDsCusvd4Service.selectPaeaDsCusvd4ById(id);
        mmap.put("paeaDsCusvd4", paeaDsCusvd4);
        return prefix + "/edit";
    }

    /**
     * 修改保存对公客户信息
     */
    @RequiresPermissions("query:paeaDsCusvd4:edit")
    @Log(title = "对公客户信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PaeaDsCusvd4 paeaDsCusvd4)
    {
        return toAjax(paeaDsCusvd4Service.updatePaeaDsCusvd4(paeaDsCusvd4));
    }

    /**
     * 删除对公客户信息
     */
    @RequiresPermissions("query:paeaDsCusvd4:remove")
    @Log(title = "对公客户信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(paeaDsCusvd4Service.removeByIds(Arrays.asList(ids.split(","))));
    }
}
